/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InvoicePane.java
 *
 * Created on 24-jul-2010, 12:32:07
 */

package facturasapp;

import facturasapp.data.DataManager;
import facturasapp.events.EventManager;
import facturasapp.events.SearchAdapter;
import facturasapp.events.SearchEvent;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BoxLayout;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.ScrollPaneLayout;
import storeDataModel.Invoice;
import sun.awt.VerticalBagLayout;

/**
 *
 * @author CiberXtrem
 */
public class SearchPreviewPane extends javax.swing.JPanel {

    /** Creates new form InvoicePane */
    public SearchPreviewPane() {
        //initComponents();
        initCustomComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setName("Form"); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 463, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 235, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
 public void initCustomComponents(){

        this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));

        //panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
        GridLayout gridLayout = new GridLayout(99,0);
        gridLayout.setVgap(0);
        panel.setLayout(gridLayout);

        this.add(labelpanel);
        this.add(scrollPane);

        scrollPane.setLayout(new ScrollPaneLayout());
        scrollPane.setPreferredSize(new Dimension(500, 160));
        scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
        scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        scrollPane.getViewport().add(panel);

        //AddListener//
        EventManager.getInstance().addSearchListener(new SearchAdapter() {

            @Override
            public void listRetrieved(SearchEvent e) {

                panel.removeAll();
                
                //DataValues
                List<Invoice >invoicesList = (List<Invoice>) e.getSource();
                Iterator it = invoicesList.iterator();

                while(it.hasNext()){
                    Invoice invoice= (Invoice) it.next();
                    ItemSearchPreviewPane invoiceItem = new ItemSearchPreviewPane(invoice);
                    //Setting values to produdShopPane

                    //Add to pane
                    panel.add(invoiceItem);
                }
                panel.revalidate();
                panel.repaint();
            }

        });
        //End AddListener//


    }



    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

    //Custom Variables
    JPanel panel = new JPanel();
    JPanel labelpanel = new SearchPreviewLabels();
    JScrollPane scrollPane = new JScrollPane();
    //End Custom Variables

    //Data Custom Variables

    //End Data Custom variables
}
